// Package app readline配置
package app

import (
	"github.com/chzyer/readline"
)

// ReadlineConfig readline配置
type ReadlineConfig struct {
	Prompt       string
	HistoryFile  string
	HistoryLimit int
	VimMode      bool
}

// DefaultReadlineConfig 默认readline配置
func DefaultReadlineConfig() ReadlineConfig {
	return ReadlineConfig{
		Prompt:       "用户输入> ",
		HistoryFile:  ".aish_history",
		HistoryLimit: 1000,
		VimMode:      false,
	}
}

// CreateReadline 创建readline实例
func CreateReadline(config ReadlineConfig) (*readline.Instance, error) {
	return readline.NewEx(&readline.Config{
		Prompt:                 config.Prompt,
		HistoryFile:            config.HistoryFile,
		InterruptPrompt:        "^C",
		EOFPrompt:              "exit",
		HistorySearchFold:      true,
		UniqueEditLine:         true,
		VimMode:                config.VimMode,
		DisableAutoSaveHistory: false,
		// 禁用可能导致问题的特殊功能
		EnableMask:   false,
		MaskRune:     0,
		HistoryLimit: config.HistoryLimit,
	})
}
